package com.hunk.core.excel.ValidatorAndProcessor;

import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.hunk.core.excel.Processor;
import com.hunk.core.excel.ProcessorChain;

/** 检查是否为空的验证器
 * @author Dengyx
 */
@Component
@Scope("prototype")
public class NullValidator extends Processor {

	public NullValidator() {
	}
	
	@Override
	public String process(HSSFWorkbook hssfWorkbook, HSSFSheet hssfSheet,
			HSSFRow hssfRow, HSSFCell hssfCell, Map<String, String> entity, 
			String stringValue, ProcessorChain chain) {		
		if ("".equals(stringValue)) {
			StringBuilder _sb = new StringBuilder(entity.get("errorMessage"));
			entity.put("errorMessage",
					_sb.append("不能为空")
						.append("*")
						.toString());			
		} else {
			return chain.process(hssfWorkbook, hssfSheet, hssfRow, hssfCell, entity, stringValue, chain);
		}
		return stringValue;
	}
}
